<?php

/*
 * @copyright :     Ienter asia Technologies
 * @author :        HungLV
 * @version         v.1.0
 * @created         24/6/2014
 * @Description :   Controller Leave info
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Mod_leaveinfo extends MYAD_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('Mmod_leaveinfo', 'le');
        $this->load->model('Mmod_employee', 'em');
    }

    function index($page = 0) { 
        $employeeID=$this->input->post('txtEmployeeId'); 
        $employee = $this->le->getEmployee($employeeID); 
        $data = $this->le->getAllData($employeeID, $page, $employee);        
        $this->load->view('layout', $data);
    }

    function updateLeaveInfo() {
        if($this->input->post('txtApplyDateOld')!=""){
            $Year=$this->input->post('txtApplyDateOld');
        }  else {
            $Year=NULL;
        }
        $employeeID=$this->input->post('txtEmployeeId');      
        
        $temp = array();
        // check exist
//        if($Year!=NULL && $employeeID!=0 && !$this->le->checkExist($employeeID,$Year)){
//            redirect('employee');
//        }
        if (isset($_POST['btnSubmit'])) {
            $validateFlag = $this->le->validate();
            if ($validateFlag) {
                /* validate success */
                $id = $this->input->post('txtEmployeeId');
                $temp = $this->le->updateLeaveInfoData($id, $Year);
            }
        }
        $employee = $this->le->getEmployee($employeeID);
        $data = $this->le->getAddLeaveInfo($employeeID, $Year, $employee);
        //var_dump($data); die;
        $this->load->view('layout', array_merge($data, $temp));
    }
    /*
     * @author :        Hunglv
     * @created:        
     * @Input :         
     * @Description:    Check min specail date input
     */    
    function min_date($str){
        if($str!=''){
            if(date('Y', strtotime($str))==$this->input->post('cboYear')){
                return TRUE;
            }
            else{
                $this->form_validation->set_message('min_date', '%s ' . $this->lang->line('emp_li_morethannow'));
                return FALSE;
            }
        }
    }
}

?>